package com.accp.vehiclecare.biz.xzhbiz;

import com.accp.vehiclecare.dao.xzhdao.ArtisanGradeDao;
import com.accp.vehiclecare.vo.xzhvo.ArtisanGradeVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service("ArtisanGradeBiz")
public class ArtisanGradeBiz extends ServiceImpl<ArtisanGradeDao, ArtisanGradeVO> {

    /**
     * 查询技工星级
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED, readOnly = true)
    public PageInfo<ArtisanGradeVO> queryArtisanGrade(Integer pageNum,Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        QueryWrapper<ArtisanGradeVO> qw = new QueryWrapper<ArtisanGradeVO>();
        qw.orderByDesc("starid");
        return new PageInfo<ArtisanGradeVO>(super.baseMapper.selectList(qw));
    }

    /**
     * 新增技工星级
     * @param artisanGradeVO
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean addArtisanGrade(ArtisanGradeVO artisanGradeVO){
        int count = super.baseMapper.insert(artisanGradeVO);
        return count!=0;
    }

    /**
     * 修改技工星级
     * @param artisanGradeVO
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean amendArtisanGrade(ArtisanGradeVO artisanGradeVO){
        int count =super.baseMapper.updateById(artisanGradeVO);
        return count != 0;
    }

    /**
     * 删除技工星级
     * @param id
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean removeArtisanGrade(Integer id){
        int count = super.baseMapper.deleteById(id);
        return count !=0;
    }

    /**
     * 查询星级
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED, readOnly = true)
    public List<ArtisanGradeVO> queryArtisanGradeVO(){
        QueryWrapper<ArtisanGradeVO> qw = new QueryWrapper<ArtisanGradeVO>();
        qw.orderByDesc("starid");
        return super.baseMapper.selectList(qw);
    }
}
